package it.orma.iridehr.controllers;

import java.util.Collections;
import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.fileupload.FileItem;

import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.multipart.MultipartException;

import org.springframework.web.multipart.commons.CommonsMultipartResolver;

public class MultiCommonsMultipartResolver extends CommonsMultipartResolver {
    
	@Override
    protected MultipartParsingResult parseRequest(HttpServletRequest request) throws MultipartException {
        try {        	        	
        	
        	String tipoUpload = request.getParameter("tipoUpload");
        	
        	if ("doc".equals(tipoUpload)){
        		setMaxUploadSize(10485760);
        	}else{
        		setMaxUploadSize(1048576);
        	}
        	
            return super.parseRequest(request);
        } catch (MaxUploadSizeExceededException e) {
            request.setAttribute("MaxUploadSizeExceededException", e);
            e.printStackTrace();
            return parseFileItems(Collections.<FileItem> emptyList(), null);
        }
    }
    
}
